<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java锁机制深度解析：从超市储物柜到高并发实战</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
            color: #222;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
        }
        .code-block {
            background: #282c34;
            border-left: 4px solid #4b6cb7;
        }
        .comparison-table {
            border-collapse: separate;
            border-spacing: 0;
            border-radius: 8px;
            overflow: hidden;
        }
        .comparison-table th, .comparison-table td {
            border: 1px solid #e2e8f0;
            padding: 12px 16px;
        }
        .comparison-table th {
            background-color: #f7fafc;
            font-weight: 600;
        }
        .comparison-table tr:nth-child(even) {
            background-color: #f8fafc;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background: rgba(118, 182, 196, 0.3);
            z-index: -1;
            transition: height 0.3s ease;
        }
        .highlight:hover:after {
            height: 50%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4">Java锁机制深度解析</h1>
                    <p class="text-xl text-blue-100 mb-6">从超市储物柜到高并发实战</p>
                    <div class="bg-blue-800 bg-opacity-50 p-4 rounded-lg border-l-4 border-blue-400">
                        <p class="text-blue-100 italic">"理解锁机制就像掌握超市储物柜的钥匙 - 简单自动的synchronized，或是功能强大的ReentrantLock，每种选择都会影响你的并发程序性能"</p>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1739844135439-f9aeab65-7748-4f97-830a-65a2c5577540.png" 
                         alt="超市储物柜比喻" 
                         class="rounded-lg shadow-xl w-full h-auto object-cover">
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-5xl">
        <!-- Introduction Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-shopping-cart text-blue-500 mr-3"></i>
                        <span class="highlight">开篇故事：超市储物柜的启示</span>
                    </h2>
                    <div class="flex flex-col md:flex-row gap-8">
                        <div class="md:w-1/2">
                            <p class="text-lg text-gray-700 mb-6">假设你第一次去超市购物，发现两种储物柜：</p>
                            <ul class="space-y-4 mb-6">
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">1</span>
                                    <span><strong>普通储物柜（synchronized）</strong>：投入硬币自动上锁，取出物品自动开锁</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-green-100 text-green-800 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">2</span>
                                    <span><strong>智能储物柜（ReentrantLock）</strong>：支持指纹解锁、预约柜门、查看使用记录</span>
                                </li>
                            </ul>
                            <p class="text-gray-700">这两种储物柜正是Java中两种锁机制的完美隐喻。接下来让我们通过一个真实的电商项目案例，揭开它们的区别之谜。</p>
                        </div>
                        <div class="md:w-1/2">
                            <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1739844135439-f9aeab65-7748-4f97-830a-65a2c5577540.png" 
                                 alt="超市储物柜图示" 
                                 class="rounded-lg shadow-md h-full w-full object-cover">
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Accident Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-exclamation-triangle text-red-500 mr-3"></i>
                        <span class="highlight">血泪史：618大促的库存超卖事故</span>
                    </h2>
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">事故背景</h3>
                    <p class="text-gray-700 mb-6">某电商平台在618大促期间，100台特价手机竟然卖出了123台！事后排查发现是并发锁机制使用不当导致。</p>
                    
                    <div class="mb-6">
                        <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1739844171592-6423c9ea-e81c-4b1f-bd3a-bfa61f64c1d5.png" 
                             alt="库存超卖事故图示" 
                             class="rounded-lg shadow-md w-full h-auto">
                    </div>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">事故代码重现</h3>
                    <div class="code-block rounded-lg mb-6 overflow-hidden">
                        <pre class="text-gray-300 p-4 overflow-x-auto"><code class="language-java">public class DisasterService {
    private int stock = 100;
    
    // 问题代码：天真的锁使用方式
    public void purchase() {
        if(stock > 0) {
            try {
                Thread.sleep(10); // 模拟网络延迟
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            stock--;
        }
    }
}</code></pre>
                    </div>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">问题分析</h3>
                    <p class="text-gray-700 mb-4">当1000个用户同时抢购时：</p>
                    <ol class="list-decimal list-inside space-y-2 text-gray-700 mb-6">
                        <li>线程A检查库存为100</li>
                        <li>线程B也检查库存为100</li>
                        <li>两个线程都进入购买流程</li>
                        <li>最终库存变成98（实际应该减少2）</li>
                    </ol>
                    <div class="bg-red-50 border-l-4 border-red-500 p-4 rounded-r">
                        <p class="text-red-700 font-medium">这就是典型的<strong>并发修改问题</strong>，接下来我们分别用两种锁机制来解决。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Synchronized Solution -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-lock text-blue-500 mr-3"></i>
                        <span class="highlight">synchronized解决方案：简单可靠的"自动锁"</span>
                    </h2>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">改造代码</h3>
                    <div class="code-block rounded-lg mb-6 overflow-hidden">
                        <pre class="text-gray-300 p-4 overflow-x-auto"><code class="language-java">public class SyncSolution {
    private int stock = 100;
    
    public synchronized void safePurchase() {
        if(stock > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            stock--;
        }
    }
}</code></pre>
                    </div>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">核心特点</h3>
                    <div class="grid md:grid-cols-3 gap-6 mb-6">
                        <div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
                            <div class="text-blue-600 mb-2">
                                <i class="fas fa-sync-alt text-xl"></i>
                            </div>
                            <h4 class="font-semibold text-blue-800 mb-2">自动上锁/释放</h4>
                            <p class="text-gray-700">像自动感应门</p>
                        </div>
                        <div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
                            <div class="text-blue-600 mb-2">
                                <i class="fas fa-redo text-xl"></i>
                            </div>
                            <h4 class="font-semibold text-blue-800 mb-2">可重入性</h4>
                            <p class="text-gray-700">同一个线程可重复获取锁</p>
                        </div>
                        <div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
                            <div class="text-blue-600 mb-2">
                                <i class="fas fa-code text-xl"></i>
                            </div>
                            <h4 class="font-semibold text-blue-800 mb-2">代码简洁</h4>
                            <p class="text-gray-700">只需一个关键字</p>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">底层原理</h3>
                    <div class="mb-6">
                        <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1739843963515-18800427-cb5d-4e79-9f09-c39c7cd04dea.png" 
                             alt="synchronized原理图示" 
                             class="rounded-lg shadow-md w-full h-auto">
                    </div>
                </div>
            </div>
        </section>

        <!-- ReentrantLock Solution -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-unlock-alt text-green-500 mr-3"></i>
                        <span class="highlight">ReentrantLock解决方案：功能强大的"手动挡"</span>
                    </h2>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">改造代码</h3>
                    <div class="code-block rounded-lg mb-6 overflow-hidden">
                        <pre class="text-gray-300 p-4 overflow-x-auto"><code class="language-java">public class LockSolution {
    private int stock = 100;
    private final ReentrantLock lock = new ReentrantLock(true); // 公平锁
    
    public void safePurchase() {
        lock.lock(); // 手动上锁
        try {
            if(stock > 0) {
                Thread.sleep(10);
                stock--;
            }
        } finally {
            lock.unlock(); // 必须手动释放
        }
    }
}</code></pre>
                    </div>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">核心特点</h3>
                    <div class="grid md:grid-cols-3 gap-6 mb-6">
                        <div class="bg-green-50 p-4 rounded-lg border border-green-100">
                            <div class="text-green-600 mb-2">
                                <i class="fas fa-sliders-h text-xl"></i>
                            </div>
                            <h4 class="font-semibold text-green-800 mb-2">灵活控制</h4>
                            <p class="text-gray-700">可中断、可超时</p>
                        </div>
                        <div class="bg-green-50 p-4 rounded-lg border border-green-100">
                            <div class="text-green-600 mb-2">
                                <i class="fas fa-balance-scale text-xl"></i>
                            </div>
                            <h4 class="font-semibold text-green-800 mb-2">公平锁</h4>
                            <p class="text-gray-700">先到先得</p>
                        </div>
                        <div class="bg-green-50 p-4 rounded-lg border border-green-100">
                            <div class="text-green-600 mb-2">
                                <i class="fas fa-cogs text-xl"></i>
                            </div>
                            <h4 class="font-semibold text-green-800 mb-2">条件变量</h4>
                            <p class="text-gray-700">精细控制等待/唤醒</p>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">高级功能演示</h3>
                    <div class="code-block rounded-lg mb-6 overflow-hidden">
                        <pre class="text-gray-300 p-4 overflow-x-auto"><code class="language-java">// 尝试获取锁（5秒超时）
if(lock.tryLock(5, TimeUnit.SECONDS)) {
    try {
        // 业务逻辑
    } finally {
        lock.unlock();
    }
}

// 条件变量应用
Condition notEmpty = lock.newCondition();
public void awaitStock() throws InterruptedException {
    lock.lock();
    try {
        while(stock == 0) {
            notEmpty.await(); // 释放锁并等待
        }
    } finally {
        lock.unlock();
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Comparison Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-balance-scale-right text-purple-500 mr-3"></i>
                        <span class="highlight">全方位对比：九大维度深度解析</span>
                    </h2>
                    
                    <div class="overflow-x-auto">
                        <table class="comparison-table w-full">
                            <thead>
                                <tr>
                                    <th class="text-left">对比维度</th>
                                    <th class="text-center">synchronized</th>
                                    <th class="text-center">ReentrantLock</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="font-medium">锁类型</td>
                                    <td>JVM内置锁</td>
                                    <td>JDK实现类</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">锁释放</td>
                                    <td>自动释放</td>
                                    <td>必须手动unlock()</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">中断响应</td>
                                    <td>不支持</td>
                                    <td>支持lockInterruptibly()</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">公平性</td>
                                    <td>非公平</td>
                                    <td>可选公平/非公平</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">性能</td>
                                    <td>JDK6后优化相当不错</td>
                                    <td>高并发下表现更好</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">条件变量</td>
                                    <td>只能配合wait()/notify()</td>
                                    <td>支持多个Condition</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">代码复杂度</td>
                                    <td>简单</td>
                                    <td>需要try-finally保护</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">锁状态查询</td>
                                    <td>无法查询</td>
                                    <td>提供isLocked()等方法</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">适用场景</td>
                                    <td>简单同步需求</td>
                                    <td>复杂并发控制</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Test -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-tachometer-alt text-orange-500 mr-3"></i>
                        <span class="highlight">实战性能测试：10万并发抢购对比</span>
                    </h2>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">测试环境</h3>
                    <ul class="flex flex-wrap gap-4 mb-6">
                        <li class="bg-gray-100 px-4 py-2 rounded-full text-sm font-medium">CPU：8核 Intel i7</li>
                        <li class="bg-gray-100 px-4 py-2 rounded-full text-sm font-medium">内存：16GB</li>
                        <li class="bg-gray-100 px-4 py-2 rounded-full text-sm font-medium">JDK：17</li>
                    </ul>
                    
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">测试结果</h3>
                    <div class="overflow-x-auto">
                        <table class="comparison-table w-full mb-6">
                            <thead>
                                <tr>
                                    <th class="text-left">指标</th>
                                    <th class="text-center">synchronized</th>
                                    <th class="text-center">ReentrantLock</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="font-medium">吞吐量（ops/ms）</td>
                                    <td>2356</td>
                                    <td>2841</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">平均响应时间（ms）</td>
                                    <td>4.2</td>
                                    <td>3.5</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">CPU占用率</td>
                                    <td>78%</td>
                                    <td>85%</td>
                                </tr>
                                <tr>
                                    <td class="font-medium">内存消耗（MB）</td>
                                    <td>512</td>
                                    <td>534</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded-r">
                        <p class="text-blue-700 font-medium">测试结论：ReentrantLock在高并发下表现更优，但资源消耗略高</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-check-circle text-teal-500 mr-3"></i>
                        <span class="highlight">最佳实践：选择锁的六大场景指南</span>
                    </h2>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                                <i class="fas fa-thumbs-up text-blue-500 mr-2"></i>
                                推荐synchronized
                            </h3>
                            <ol class="list-decimal list-inside space-y-3 text-gray-700 pl-2">
                                <li>简单的代码块同步</li>
                                <li>对象级别锁足够时</li>
                                <li>需要最低限度的代码侵入</li>
                            </ol>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                                <i class="fas fa-bolt text-green-500 mr-2"></i>
                                推荐ReentrantLock
                            </h3>
                            <ol class="list-decimal list-inside space-y-3 text-gray-700 pl-2">
                                <li>需要尝试获取锁（tryLock）</li>
                                <li>需要公平锁机制</li>
                                <li>需要分离的等待条件</li>
                                <li>需要获取锁的状态信息</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Common Mistakes -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-exclamation-circle text-red-500 mr-3"></i>
                        <span class="highlight">常见误区与陷阱</span>
                    </h2>
                    
                    <div class="space-y-8">
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-3">误区1：锁的范围过大</h3>
                            <div class="code-block rounded-lg mb-4 overflow-hidden">
                                <pre class="text-gray-300 p-4 overflow-x-auto"><code class="language-java">// 错误示范：锁住整个方法
public synchronized void process() {
    // 只有这部分需要同步
    doSomething();
    // 其他无关操作
}</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-3">误区2：忘记释放ReentrantLock</h3>
                            <div class="code-block rounded-lg mb-4 overflow-hidden">
                                <pre class="text-gray-300 p-4 overflow-x-auto"><code class="language-java">public void danger() {
    lock.lock();
    // 如果这里抛出异常...
    lock.unlock(); // 可能永远不会执行
}</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-3">正确姿势</h3>
                            <div class="code-block rounded-lg overflow-hidden">
                                <pre class="text-gray-300 p-4 overflow-x-auto"><code class="language-java">public void safeMethod() {
    lock.lock();
    try {
        // 业务代码
    } finally {
        lock.unlock();
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Principles -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-microscope text-purple-500 mr-3"></i>
                        <span class="highlight">锁的底层原理探秘</span>
                    </h2>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-4">synchronized的锁升级过程</h3>
                            <ol class="list-decimal list-inside space-y-3 text-gray-700 mb-4">
                                <li><strong>无锁状态</strong>：新创建对象</li>
                                <li><strong>偏向锁</strong>：单线程访问时</li>
                                <li><strong>轻量级锁</strong>：少量线程竞争</li>
                                <li><strong>重量级锁</strong>：高并发竞争</li>
                            </ol>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-4">ReentrantLock的AQS原理</h3>
                            <p class="text-gray-700 mb-4">AbstractQueuedSynchronizer（AQS）通过CLH队列管理线程：</p>
                            <ol class="list-decimal list-inside space-y-3 text-gray-700">
                                <li>线程请求锁时加入队列</li>
                                <li>通过CAS操作修改状态</li>
                                <li>实现公平/非公平调度</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Final Choice -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover transition-all duration-300">
                <div class="p-8">
                    <h2 class="text-3xl font-bold mb-6 flex items-center">
                        <i class="fas fa-flag-checkered text-indigo-500 mr-3"></i>
                        <span class="highlight">终极选择：什么时候用哪个锁？</span>
                    </h2>
                    
                    <p class="text-gray-700 mb-8">通过本文的实战案例和对比分析，我们可以得出以下结论：</p>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div class="bg-blue-50 p-6 rounded-lg border border-blue-200">
                            <h3 class="text-xl font-bold text-blue-800 mb-4 flex items-center">
                                <i class="fas fa-check text-blue-600 mr-2"></i>
                                选择synchronized当：
                            </h3>
                            <ul class="space-y-3 text-gray-700 pl-2">
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>需要快速实现基本同步</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>不需要高级锁特性</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-blue-500 mt-1 mr-2 text-sm"></i>
                                    <span>希望减少代码复杂度</span>
                                </li>
                            </ul>
                        </div>
                        <div class="bg-green-50 p-6 rounded-lg border border-green-200">
                            <h3 class="text-xl font-bold text-green-800 mb-4 flex items-center">
                                <i class="fas fa-bolt text-green-600 mr-2"></i>
                                选择ReentrantLock当：
                            </h3>
                            <ul class="space-y-3 text-gray-700 pl-2">
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-green-500 mt-1 mr-2 text-sm"></i>
                                    <span>需要细粒度控制锁</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-green-500 mt-1 mr-2 text-sm"></i>
                                    <span>需要处理复杂等待条件</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-green-500 mt-1 mr-2 text-sm"></i>
                                    <span>追求更高性能</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto px-6 max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <p class="text-lg font-medium">技术小馆</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors duration-200">
                        <i class="fas fa-globe mr-2"></i>
                        http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
            }
        });
    </script>
</body>
</html>